﻿using Mes.Application.DTO.Results.Operations;
using Mes.Domain.BoundedContext;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mes.Application.DTO.Results.WorkOrders
{
    /// <summary>
    /// 工单出参
    /// </summary>
    public class WoBaseResult
    {
        /// <summary>
        /// 工单编号
        /// </summary>
        public string Wo_Id { get; set; } = string.Empty;

        /// <summary>
        /// 工单名称（描述）
        /// </summary>
        public string? Wo_Desc { get; set; }

        /// <summary>
        /// 生产成品Id
        /// </summary>
        public int Item_Id { get; set; }

        /// <summary>
        /// 生产成品名称
        /// </summary>
        public string? Item_Name { get; set; }  

        /// <summary>
        /// 状态 0 = Released, 1 = Started, 2 = Completed, 3 = Closed
        /// </summary>
        public int State_Cd { get; set; }

        /// <summary>
        /// 开工数量
        /// </summary>
        public double Start_Qty { get; set; }

        /// <summary>
        /// 所需产量
        /// </summary>
        public double Req_Qty { get; set; }

        /// <summary>
        /// 投产日期/时间
        /// </summary>
        public DateTime? Release_Time_Local { get; set; }

        /// <summary>
        /// 所需完工日期/时间
        /// </summary>
        public DateTime? Req_Finish_Time_Local { get; set; }

        /// <summary>
        /// 最迟开工日期/时间
        /// </summary>
        public DateTime? Latest_Start_Time_Local { get; set; }

        /// <summary>
        /// 调度完工日期/时间
        /// </summary>
        public DateTime? Sched_Finish_Time_Local { get; set; }

        /// <summary>
        /// 优先级
        /// </summary>
        public int? Wo_Priority { get; set; }
    }

    /// <summary>
    /// 查询工单实体出参
    /// </summary>
    public class WoResult : WoBaseResult { }

    /// <summary>
    /// 分页查询工单列表出参
    /// </summary>
    public class WosResult : WoBaseResult
    {
        /// <summary>
        /// 作业列表
        /// </summary>
        public List<JobResult> JobResults { get; set; } = new List<JobResult>();
    }

    /// <summary>
    /// 工艺关联物料，以及物料BOM
    /// </summary>
    public class ProcessForWoResult
    {
        /// <summary>
        /// 工艺ID
        /// </summary>
        public string Process_Id { get; set; } = string.Empty;

        /// <summary>
        /// 工艺描述
        /// </summary>
        public string Process_Desc { get; set; } = string.Empty;

        /// <summary>
        /// 工艺仅仅关联一个物料
        /// </summary>
        public MaterialForWoResult Material { get; set; } = new MaterialForWoResult();
    }

    public class MaterialForWoResult
    {
        /// <summary>
        /// 物料Id
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 物料名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 一个物料关联多个物料清单
        /// </summary>
        public IList<IdNameResult> MaterialBOMs { get; set; } = new List<IdNameResult>();
    }

    public class MaterialBOMResults : MaterialForWoResult
    {
        public MaterialBOMResults(int materialId, string materialName, int measuringUnitId, string measuringUnitName, IList<IdNameResult> materialBOMs)
        {
            Id = materialId;
            Name = materialName;
            MeasuringUnitId = measuringUnitId;
            MeasuringUnitName = measuringUnitName;
            foreach (var item in materialBOMs)
            {
                var bom = new IdNameResult(item.Id, item.Name);
                MaterialBOMs.Add(bom);
            }
        }

        /// <summary>
        /// 计量单位Id
        /// </summary>
        public int MeasuringUnitId { get; set; }

        /// <summary>
        /// 计量单位名称
        /// </summary>
        public string MeasuringUnitName { get; set; }
    }


    public class WoJobRoutesResult
    {
        /// <summary>
        /// 操作编号
        /// </summary>
        public string Oper_Id { get; set; } = string.Empty;
    }
}
